/**
* Copyright (c) 2016-2100 yunclouds
*/
package com.yunqian.web;

import com.yunqian.redot.domain.Role;
import com.yunqian.redot.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * Describe: 控制器
 *
 * @author zsy
 * 2018-11-08 09:41:18
 */
 @RestController
 @RequestMapping("/api/role")
public class RoleController {

     @Autowired
     private RoleService roleService;

    /**
     * 获取分页
     *
     * @param params
     * @return
     */
    @PostMapping("/pagination")
    public Page<Role> pagination(@RequestBody Map<String, Object> params) {
        params.put("_filter_noeq_id", 1L);
        return roleService.pagination(params);
    }

     /**
     * 获取所有列表
     *
     * @return
     */
    @GetMapping("/all")
    public Map<String, Object> list() {
        List<Role> roleList = roleService.findAll();
        Map<String, Object> map = new HashMap<>();
        map.put("roleList", roleList);
        return map;
    }

    /**
     * 添加
     *
     * @param role 对象信息
     */
    @PostMapping
    public Role save(@RequestBody @Valid Role role) {
        roleService.save(role);
        return role;
    }

    /**
     * 局部更新数据
     *
     * @param id         待更新id
     * @param modifyData 待更新的数据
     * @return
     */
    @PutMapping("/{id}")
    public Role update(@PathVariable("id") Long id, @RequestBody Map<String, Object> modifyData) {
        return roleService.update(id, modifyData);
    }

    /**
     * 根据id获取详情
     *
     * @param id 要查询的船只id
     * @return
     */
    @GetMapping("/{id}")
    public Role detail(@PathVariable("id") Long id) {
        return roleService.findStrictOne(id);
    }

}
